bangkeapp.factory('carService', ['$http', '$q', 'url', "userinfoService", "$ionicLoading",
function($http, $q, url, userinfoService, $ionicLoading) {
	
    var iscarmember = function(memberid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/iscarmember/querycarmember?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    var getbymembername = function(membername) {
		var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var result = {};
		var member = {};
		member.membername = membername;
        var data = userinfoService.getData();
		data.request.body.member = []
		data.request.body.member[0] = member;
    		
		$http({    
            method: "JSONP",    
            url: url + "/member/getbymembername?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			if ("M" == response.Response.Header.ResponseCode) {
				result = response;
				progress = true;
			} else {
				progress = false;
			}
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
	}
    var registercarqueryredpacket = function(memberid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/registerinit/queryredpacket?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    var carregister = function(memberid, referenceid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
		data.body.referenceid = referenceid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/submitregisterinit/saveSubmitApply?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    var querycarindexinit = function(memberid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/carindexinit/queryCarIndexInit?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    
    var querybuycarindex = function(memberid, status){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
		data.body.status = status;
    		
		$http({    
            method: "JSONP",    
            url: url + "/buycarindex/queryBuyCarIndex?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    
    var querydrawals = function(memberid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/withdrawalsRecord/queryWithdrawalsRecord?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    var savebuycarapply = function(apply){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body = apply;
    		
		$http({    
            method: "JSONP",    
            url: url + "/buycarapply/saveBuyCarApply?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    var selectlstapplyinfo = function(memberid){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/applyinfo/selectLstApplyInfo?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    
    var savequitcarapply = function(){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = userinfoService.getUser().memberid;
    		
		$http({    
            method: "JSONP",    
            url: url + "/quitcarapply/saveQuitcarapply?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    
    var confirmpayment = function(securepwd){
        var deferred = $q.defer();
        var promise = deferred.promise;
        var progress;
        var data = userinfoService.getNewData();
		data.body.memberid = userinfoService.getUser().memberid;
		data.body.securepwd = securepwd;
    		
		$http({    
            method: "JSONP",    
            url: url + "/securepwdchange/confirmPayment?callback=JSON_CALLBACK",  
            params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {
			
			var result = response;
			progress = "正确";
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
    }
    
    return {
        iscarmember: iscarmember, // 是否是帮客汽车会员
        getbymembername : getbymembername, // 查询其他会员, 1:推荐人
        registercarqueryredpacket : registercarqueryredpacket, // 注册汽车会员的时候查询要扣除的红包积分
        carregister : carregister, // 帮客汽车激活
        querycarindexinit : querycarindexinit, // 帮客汽车首页初始化
        querybuycarindex : querybuycarindex, // 查询会员的购车信息及促成人
        querydrawals : querydrawals, // 提现记录
        savebuycarapply : savebuycarapply,
        selectlstapplyinfo : selectlstapplyinfo, // 提现记录(小胖)
        savequitcarapply : savequitcarapply, // 退出
        confirmpayment : confirmpayment
        
   	}
}
]);